package com.example.mapper;

import com.example.pojo.entity.Chat;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * 所学内容:
 *
 * @author ..
 * @Date 2023/10/28 14:20
 */
public interface ChatMapper {
    @Select("select * from chat where js_id=${jsId} and jr_id=${jrId}")
    public Chat findByJsJrID(@Param("jsId")Integer jsId,@Param("jrId")Integer jrId);

    @Delete("delete from chat where js_id=${jsId} and jr_id=${jrId}")
    public int deleteByJsJrID(@Param("jsId")Integer jsId,@Param("jrId")Integer jrId);

    @Insert("insert into chat(jr_id,jr_name,jr_avatar,js_id,js_name,js_avatar) value(#{jrId},#{jrName},#{jrAvatar},#{jsId},#{jsName},#{jsAvatar})")
    public int insertJsJr(@Param("jrId") Integer jrId,@Param("jrName") String jrName,@Param("jrAvatar") String jrAvatar,@Param("jsId") Integer jsId,@Param("jsName") String jsName,@Param("jsAvatar") String jsAvatar);

    @Update("update chat set last_chat_time=#{lastTime} where id=#{id}")
    public int updateLastTime(@Param("lastTime")Date lastTime,@Param("id")Integer id);

    @Select("select * from chat where js_id=#{value}")
    public List<Chat> findByJsId(Integer jsId);

    @Select("select * from chat where jr_id=#{value}")
    public List<Chat> findByJrId(Integer jrId);
}
